<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>添加/编辑考核项</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form label-width="120px" ref="editForm">
          <el-form-item label="考核期限：" prop="name">
            <el-date-picker type="date"
                            placeholder="选择日期"
                            v-model="end_time"
                            :picker-options="pickerOptions1"
                            value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
          <el-form-item label="考核内容：" prop="name">
            <el-input auto-complete="off" placeholder="考核内容" v-model="content"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button @click="submitFromFn" size="small" type="primary">确定并保存</el-button>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  props: ['visible', 'assessmentId', 'resumeId'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      dialogVisible: false,
      end_time: '',
      content: '',
      // 限制时间选择
      pickerOptions1:
          {
            disabledDate(time) {
              return time.getTime() < Date.now() // - 8.64e7
            }
          },
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.InitFn()
      } else {
        this.end_time = '';
        this.content = '';
      }
    }
  },
  created() {

  },
  methods: {
    submitFromFn() {
      // 判断新增 编辑
      if (!this.end_time) {
        this.$message.error('选择考核期')
        return
      }
      if (!this.content) {
        this.$message.error('填写考核内容')
        return
      }
      let dataOption = {
        resume_id: this.resumeId,
        content: this.content,
        end_time: this.end_time
      };
      let url_ = this.api.recruit.examine.add;
      if (this.assessmentId) {
        url_ = this.api.recruit.examine.edit;
        dataOption.id = this.assessmentId;
      }
      this.$post(url_, dataOption).then((response) => {
        if (!response.code) {
          this.$message.success(response.msg)
          this.$emit('InitFn')
        } else {
          this.$message.error(response.msg)
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    // 获取详情
    async InitFn() {
      if (this.assessmentId) {
        let data = await this.$fetch(this.api.recruit.examine.edit, {id: this.assessmentId});
        if (!data.code) {
          this.end_time = data.vo.end_time;
          this.content = data.vo.content;
        } else {
          this.$message.error(data.msg)
        }
      }
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 50%;
  height: 30%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
  z-index: 9;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}
</style>


